<?
layout("/inc/layout.html",{title:sysTitle}){
?>
<script type="text/javascript" src="static/utf8-jsp/ueditor.config.js"></script>
<script type="text/javascript" src="static/utf8-jsp/ueditor.all.js"></script>
<script type="text/javascript" src="static/utf8-jsp/lang/zh-cn/zh-cn.js"></script>
<script type="text/javascript" src="static/utf8-jsp/third-party/video-js/video.js"></script>
<div id="page-wrapper">
	<!--BEGIN TITLE & BREADCRUMB PAGE-->
	<div id="title-breadcrumb-option-demo" class="page-title-breadcrumb">
		<div class="page-header pull-left">
			<div class="page-title">知识字典管理</div>
		</div>
		<ol class="breadcrumb page-breadcrumb pull-left">
			<li><i class="fa fa-home"></i>&nbsp;<a href="main.html">首页</a>&nbsp;&nbsp;<i
				class="fa fa-angle-right"></i>&nbsp;&nbsp;</li>
			<li>知识字典管理&nbsp;&nbsp;</i>&nbsp;&nbsp;</li>
		</ol>
		<div class="clearfix"></div>
	</div>
	<!--END TITLE & BREADCRUMB PAGE-->
	<!--BEGIN CONTENT-->
	<div class="page-content">


		<div class="row mbl">
			<div class="col-lg-6">
				<div class="input-group input-group-sm mbs">

					<span class="input-group-btn">
						<select id="queryParams" data-toggle="dropdown" class="btn btn-danger dropdown-toggle" style="width :100px;">
		                    <option value="-1">筛选项&nbsp;<span class="caret"></span></option>
		                    <option value="nameZh">中文名称</option>
		                    <option value="nameEn">英文名称</option>
                    	</select>
                   </span> 
                    	<input id="text" type="text" placeholder="请输入关键词..." class="form-control" />
                   <span class="input-group-btn">
                   		<button type="button" data-toggle="dropdown" class="btn btn-success dropdown-toggle" onclick="get()">搜索</button>
				   </span>

				</div>
			</div>
			<div class="col-lg-6">
				<div class="tb-group-actions pull-right">
				 <!--	<span>当前已选择10条记录:</span> 
					<button class="btn btn-sm btn-primary">
						<i class="fa fa-check"></i>&nbsp; 提交
					</button>   -->
					<button class="btn btn-sm btn-primary" onclick="addUpdateDict('0')">新增</button>
					<button class="btn btn-sm btn-primary" onclick="solrPublish()">发布</button>
					<button class="btn btn-sm btn-primary" onclick="deleteDictAll()">删除选中</button>
					<button class="btn btn-sm btn-primary" onclick="upFiles()">导入</button>
					<button class="btn btn-sm btn-primary" onclick="vocabularyDict()">下载导出说明</button>
				</div>
			</div>
		</div>

		<table
			class="table table-hover table-striped table-bordered table-advanced tablesorter mbn">
			<thead>
				<tr>
					<th><input type="checkbox" onclick="selectAll(this)" class="checkall" name="oncheckall" /></th>
					<th width="8%">序号</th>
					<th>中文名称</th>
					<th>英文名称</th>
					<th>类型</th>
					<th>排序</th>
					<th width="25%">操作</th>
				</tr>
			</thead>
			<tbody id="findDict"></tbody>
		</table>
		<div id="dataNull" class="panel-body"
				style="height: 90px; line-height: 50px;" align="center">
		</div>
		<div id="page2" style="text-align: center; margin-top: 20px;"></div>
	</div>
<textarea id="uploadImage" name="uploadImage" ></textarea>
	<!--END CONTENT-->
</div>
<form action="./dictItemExportList.do" method="post" name="aa" target="_blank">
</form>
<form action="downloadDict.do" method="post" name="bb" target="_blank"></form>
<?} ?>
<script>
	var curr;
	var id;
	var sum;
	var newspage;
	var _editor;
	function getsum() {
		return sum+1;
	}
	function getCurr() {
		return newspage;
	}
	$(function() {
		demo1(newspage);
		_editor = UE.getEditor('uploadImage');
	    _editor.ready(function (){
	        //设置编辑器不可用(事实上不可以设置不可用...所以注释掉,以观后效)
	        _editor.setDisabled();
	        //隐藏编辑器,因为只使用上传功能
	        _editor.hide();
	        //侦听图片上传
	  	 	_editor.addListener('beforeInsertImage',function(t,arg){
	  	 		
	        });
	        //侦听文件上传
		   	 _editor.addListener('afterUpfile',function(t,arg){
		   	 	//for(var i=0;i<arg.length;i++){
	  	 			importDict(arg[0].url);
	  	 		//}
		   	 });
	   });
	});
	function get() {
	};
	function getlay() {
		return id;
	};
	/* var setting = {
	callback : {
				onClick : onClick
			},
	}; */
	function exportDict(eid){
	layer.msg('请选择导出格式', {
		  btn: ['xml', 'Excel'],
		  yes: function(index){
		    layer.close(index);
		    var _downiframe = $("iframe#_downiframe");
			if (_downiframe.length == 0) {
				_downiframe =$("<iframe id='_downiframe' name='_downiframe' style='display:none'></iframe>").appendTo($("body"));
			}
			_downiframe.attr("src", "exportDict.do?id="+eid+"&type=xml");
		  },
		  cancel : function(index) {
		  	var _downiframe = $("iframe#_downiframe");
			if (_downiframe.length == 0) {
				_downiframe =$("<iframe id='_downiframe' name='_downiframe' style='display:none'></iframe>").appendTo($("body"));
			}
			_downiframe.attr("src", "exportExcelDict.do?id="+eid+"&type=Excel");
			
		  }
		});
	}
	function showDictitemBiaoge(lidBiaoge) {
		id = lidBiaoge;
		layer.open({	
		 	type: 2,
    	    scrollbar: true,
    	    shadeClose: true,
    	    title : '字典项管理',
    	    move: false, 	    
			area : [ '800px', '600px' ],
			skin: 'layui-layer-rim', //加上边框
    	    btn: ['关闭'],
			fix : false, //不固定
			maxmin : true,
			content : ["show-findall-dictitem-biaoge.html",'no']
		});
	};
	function showDictitemzTree(lidzTree) {
		id = lidzTree;
		layer.open({
			scrollbar: true,
    	    shadeClose: true,
    	    move: false, 
    	    title : '字典项管理',
			type : 2,
			area : [ '700px', '600px' ],
			fix : false, //不固定
			skin: 'layui-layer-rim', //加上边框
			btn: ['关闭'],
			//maxmin : true,
			content : ["show-findall-dictitem-zTree.html",'no']
		});
	};
	var iframeWin;
	function addUpdateDict(lid) {
		id = lid;
		layer.open({
    	    scrollbar: false,
    	    shadeClose: true,
    	    move: false, 	
    	    title : '字典类管理',    
			type : 2,
			area : [ '550px', '445px' ],
			fix : false, //不固定
			maxmin : true,
			content : ["dict-add-update.html",'no'],
			btn: ['保存 ', '关闭'],
			skin : 'layui-layer-rim', //加上边框
			yes: function(index,layer){
	                iframeWin = parent.window[layer.find('iframe')[0]['name']];
	                 iframeWin.Page();
	         },
			cancel : function(index) {
			}
		});
	};
	function del(id) {
		if (confirm("是否确认删除！！将删除字典项下所有数据！"))
		{
			$.ajax({
				type : "post",
				url : "./deldict.do",
				data : {
					"id" : id
				},
				dataType : "json",
				success : function(data) {
					if(data.count != false){
						layer.msg('该字典已被知识加工使用,不可删除!');
					}else{
						layer.msg('删除成功');
					}
					demo1(newspage);
				},
				error : function(data) {
					alert("请求失败");
				}
			});
		}
	};
	function demo1(curr) {
		
		$.getJSON(
			"./findallDict.do",
			{
				page : curr || 1,
				queryParams:$("#queryParams").val(),
		        text:$("#text").val(),
			},
			function(res) {
				sum=res.sortMuch;
				//此处仅仅是为了演示变化的内容
				var str = "";
				if( res.listsize>0){
						$("#dataNull").html("");
				}else{
					$("#dataNull").html("<span class='subtitle' style='font-size: 15px;'>数据为空!</span>");
				}
				$("#findDict").html("");
				for ( var i = 0; i < res.listsize; i++) {
					str += "<tr><td>"
							+"<input name='checkall'  type='checkbox' value='"+res.result[i].id+"'/>"
							+"</td><td>"
							+ (i + 1)
							+ "</td><td> <label id=>"
							+ res.result[i].nameZh
							+ "</label></td><td><label >"
							+ res.result[i].nameEn
							+ "</label></td><td><label >"
							+ res.result[i].dictType
							+ "</label></td><td><label >"
							+ res.result[i].sort
							+ "</label></td><td>"
							+ "<button type=\"button\" class=\"btn btn-default btn-xs\"onclick="+res.result[i].tiaozhuan+"('"
							+ res.result[i].id
							+ "')>"
							+ "字典项管理"
							+ "</button>&nbsp;"
							+ "<button type=\"button\" class=\"btn btn-default btn-xs\"  onclick=\"del('"
							+ res.result[i].id
							+ "')\">"
							+ "删除"
							+ "</button>&nbsp;"
							+ "<button type=\"button\" class=\"btn btn-default btn-xs\"  onclick=\"addUpdateDict('"
							+ res.result[i].id
							+ "')\">"
							+ "编辑"
							+ "</button>&nbsp;"
							+ "<button type=\"button\" class=\"btn btn-default btn-xs\"  onclick=\"exportDict('"
							+ res.result[i].id
							+ "')\">"
							+ "导出"
							+ "</button>" + "</td></tr>";
				}
				$("#findDict").append(str);
				laypage({
					cont : document.getElementById("page2"), //容器。值支持id名、原生dom对象，jquery对象,
					pages : res.pageSize, //总页数
					skip : true, //是否开启跳页
					curr : curr || 1,
					last: res.pageSize,
					skin : 'molv', //加载内置皮肤，也可以直接赋值16进制颜色值，如:#c00
					groups : 6,//连续显示分页数
					jump : function(obj, first) { //触发分页后的回调
						if (!first) { //点击跳页触发函数自身，并传递当前页：obj.curr
							demo1(obj.curr);
			                 curr=obj.curr;
			                 newspage = obj.curr;
						}
					}
				});
			});
		};

	//字典注解导出
	function vocabularyDict(){
		if (confirm("是否确认下载！！")) {
			document.forms['bb'].submit();
		}
	}
	
	//solr发布
	function solrPublish(){
	if (confirm("是否确认发布！！")) {
		$.ajax({
				type : "post",
				url : "solrPublish.do",
				dataType : "json",
				success : function(data) {
					if(data == 'yes'){
					 	 parent.layer.msg('发布成功!');
					 }else{
					 	 parent.layer.msg('发布失败!'); 
					 }
					demo1(newspage);
				},
				error : function(data) {
					alert("请求失败");
				}
			});
		}
	}
	function deleteDictAll() {
		if (confirm("是否确认选中删除！！")){
			var valueIds=[];
				$("input[name='checkall']:checked").each(function(){
					valueIds.push($(this).val());
				}); 
			$.ajax({
				type : "post",
				url : "./deleteDictAll.do",
				data : {
					"valueIds" : valueIds
				},
				dataType : "json",
				traditional : true,
				success : function(data) {
					if(data[0].data == 'yes'){
						demo1(curr);
						layer.msg('删除成功');
					}else{
						layer.msg('删除失败！');
					}
				},
				error : function(data) {
					alert("请求失败");
				}
			});
		}
	}
	//导入
	 //上传文件
	function upFiles() {
		var myFiles = _editor.getDialog("attachment");
	   	myFiles.open();
	}
	function importDict(urlFile){
		$.ajax({
			type : "post",
			url : "./importDict.do",
			data : {
				"urlFile" : urlFile
			},
			dataType : "json",
			traditional : true,
			success : function(data) {
				if(data[0].data == 'yes'){
					demo1(curr);
					layer.msg('导入成功');
				}else if(data[0].data == 'type'){
					layer.msg('请上传正确的xml、xls或者xlsx格式文件!');
				}else{
					layer.msg('导入失败！');
				}
			},
			error : function(data) {
				alert("请求失败");
			}
		});
	}
</script>